package com.altekis.kanbankaze.server.dao;

import java.io.Serializable;
import java.util.List;

/**
 * Generic DAO, providing CRUD operations
 * 
 * @author gabrielp
 * 
 * @param <T>
 *            the entity type
 * @param <ID>
 *            the primary key type
 */
public interface GenericDAO<T, ID extends Serializable> {

	/**
	 * delete an entity from the database.
	 * 
	 * @param entity
	 *            the entity to delete
	 */
	void delete(final T entity);

	/**
	 * Load all entities.
	 * 
	 * @return the list of entities
	 */
	List<T> findAll();

	/**
	 * Find an entity by its primary key
	 * 
	 * @param id
	 *            the primary key
	 * @return the entity
	 */
	T findById(final ID id);

	/**
	 * Flush the persistence manager
	 */
	void flush();

	/**
	 * Get the Class of the entity.
	 * 
	 * @return the class
	 */
	Class<T> getEntityClass();

	/**
	 * save an entity. This can be either a INSERT or UPDATE in the database.
	 * 
	 * @param entity
	 *            the entity to save
	 * 
	 * @return the saved entity
	 */
	T save(final T entity);
}
